<template>
  <div class="my-header">
    <!-- 折叠侧边的icon -->
    <div class="header-fl">
      <i @click="toggleSide" :class="['icon', $store.state.nav.isCollapse? 'el-icon-s-unfold': 'el-icon-s-fold']"></i>
      <div class="navs">
        <el-breadcrumb separator="/">
          <el-breadcrumb-item :to="{ path: '/admin' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item v-if="$route.path != '/dashBoard'">
            {{$route.name}}
          </el-breadcrumb-item>
        </el-breadcrumb>
      </div>
    </div>
    <div class="header-rt">
      <el-dropdown @command="clickMenuItem">
       <div class="user_info">
         <el-avatar shape="square" :size="50" :src="userInfo.avatar"></el-avatar>
         <span>{{userInfo.nickName}}</span>
       </div>
       <el-dropdown-menu slot="dropdown">
        <el-dropdown-item command="toUser">个人中心</el-dropdown-item>
        <el-dropdown-item command="toMsg">消息中心</el-dropdown-item>
        <el-dropdown-item command="logout">退出登录</el-dropdown-item>
      </el-dropdown-menu>
      </el-dropdown>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      userInfo: localStorage.getItem('userInfo')
        ? JSON.parse(localStorage.getItem('userInfo'))
        : {}
    }
  },
  methods: {
    clickMenuItem (command) {
      if (command === 'logout') {
        // 退出登录
        localStorage.removeItem('token')
        localStorage.removeItem('userInfo')
        localStorage.removeItem('role')
        this.$router.go(0)
      }
    },
    toggleSide () {
      // 点击触发 侧边打开和折叠
      this.$store.commit('nav/toggleSideMenu')
    }
  }
}
</script>

<style lang="scss" scoped>
.my-header {
  height: 100%;
  line-height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  .header-fl {
    display: flex;
    align-items: center;
  }
  .icon {
    cursor: pointer;
    font-size: 24px;
  }
  .navs {
    margin-left: 20px;
  }
  .header-rt{
    margin-right: 20px;
    height: 60px;
    .user_info{
        height: 60px;
        cursor: pointer;
        display: flex;
        align-items: center;
        span{
          font-size: 14px;
          color: #333;
          margin-left: 5px;
        }
    }
  }
}
</style>
